package com.dvhung.adapter;

import java.util.ArrayList;

import com.dvhung.model.dto.ItemDTO;
import com.dvhung.projectmvcdemo.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ItemAdapter extends ArrayAdapter<Object>{
	Context mContext;
	ArrayList<Object> arrObjects;
	
	class ViewHolder{
		TextView txt1;
	}
	public ItemAdapter(Context context, int resource, ArrayList<Object> arr) {
		super(context, resource, arr);
		mContext = context;
		arrObjects = arr;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arrObjects.size();
	}
	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return arrObjects.get(position);
	}
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rootView = inflater.inflate(R.layout.adapter_list, parent, false);
		ViewHolder holder = new ViewHolder();
		holder.txt1 = (TextView)rootView.findViewById(R.id.txt1);
		ItemDTO dto;
		Object o = (Object)arrObjects.get(position);
		dto = (ItemDTO)o;
		holder.txt1.setText(dto.getItemName());
		return rootView;
	}

}
